<template>
  <div class="table-box">
    <el-table stripe :data="dataList" size="mini" :header-cell-style="{ background: '#F5F5F5', color: '#000000' }" ref="table" style="width: 100%" v-loading="dataListLoading">
      <el-table-column align="center" header-align="center" label="独享ID" prop="number_id"></el-table-column>
      <el-table-column align="center" header-align="center" label="状态" prop="sts">
        <template slot-scope="scope"> {{ getSts(scope.row.sts) }} </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" label="推送人数" prop="pub_count"></el-table-column>
      <el-table-column align="center" header-align="center" label="未读" prop="no_read"></el-table-column>
      <el-table-column align="center" header-align="center" label="减少推荐-价钱高" prop="dec_type1"></el-table-column>
      <el-table-column align="center" header-align="center" label="减少推荐-地区太远" prop="dec_type2"></el-table-column>
      <el-table-column align="center" header-align="center" label="减少推荐-量太少" prop="dec_type3"></el-table-column>
      <el-table-column align="center" header-align="center" label="减少推荐-不感兴趣" prop="dec_type4"></el-table-column>
      <el-table-column align="center" header-align="center" label="已读" prop="view_count"></el-table-column>
      <el-table-column align="center" header-align="center" label="已联系待标注" prop="contacted"></el-table-column>
      <el-table-column align="center" header-align="center" label="已标注-成交" prop="success"></el-table-column>
      <el-table-column align="center" header-align="center" label="已标注-未成交" prop="fail"></el-table-column>
    </el-table>
    <el-pagination
      small
      background
      :current-page="pageNumber"
      :page-size="pageSize"
      :page-sizes="[10, 20, 50, 100]"
      :total="pageTotal"
      @current-change="currentChangeHandle"
      @size-change="sizeChangeHandle"
      layout="total, sizes, prev, pager, next, jumper"
      style="margin-top: 20px; text-align: right"
    ></el-pagination>
  </div>
</template>

<script>
import { apiBusinessPushDetail } from '@/api/dataStatistics'

export default {
  props: {
    time: Object,
  },
  data() {
    return {
      stsList: [
        { value: 1, label: '推送中' },
        { value: 4, label: '推送完毕' },
        { value: 2, label: '成交待核实' },
        { value: 3, label: '已成交' },
      ],
      dataList: [],
      pageNumber: 1,
      pageSize: 10,
      pageTotal: 0,
      dataListLoading: false,
    }
  },
  activated() {
    this.$refs.table.doLayout()
  },
  watch: {
    time: function () {
      this.pageNumber = 1
      this.getDataList()
    },
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    getDataList() {
      this.dataListLoading = true
      apiBusinessPushDetail({ ...this.time, pageNumber: this.pageNumber, pageSize: this.pageSize })
        .then((res) => {
          const { data, total } = res
          this.dataListLoading = false
          this.dataList = data
          this.pageTotal = total
        })
        .catch((e) => {
          this.dataList = []
          this.pageTotal = 0
          this.dataListLoading = false
        })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageNumber = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageNumber = val
      this.getDataList()
    },
    // 获取状态
    getSts(value) {
      const item = this.stsList.find((item) => item.value === value)
      if (item) {
        return item.label
      } else {
        return ''
      }
    },
  },
}
</script>

<style scoped lang="scss">
.table-box {
  margin-top: 20px;
}
</style>
